package com.crm.service.impl;


import com.crm.common.utils.DateUtils;
import com.crm.common.utils.uuid.UUIDUtils;
import com.crm.domain.Activity;
import com.crm.mapper.ActivityMapper;
import com.crm.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
@Component
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    /**
     * 查询活动列表
     * @param activity
     * @return
     */
    @Override
    public List<Activity> selectActivityList(Activity activity) {
        List<Activity> vo = activityMapper.selectActivityList(activity);
        if (vo != null) {
            return vo;
        }
        return null;
    }
    /**
     * 查询活动状态
     * @return
     */
    @Override
    public Map getCountByStatus() {
        return activityMapper.getCountByStatus();
    }
    /**
     * 根据id查询活动
     * @param id
     * @return
     */
    @Override
    public Activity getActivityById(Long id) {
        return activityMapper.getActivityById(id);
    }
    /**
     * 添加活动
     * @param activity
     * @return
     */
    @Override
    public int insertActivity(Activity activity) {
        activity.setCreateTime(DateUtils.getNowDate());
        activity.setCode(UUIDUtils.getUUID());
        activity.setStatus("2");
        int i = activityMapper.insertActivity(activity);
        return i;
    }
    /**
     * 修改活动
     * @param activity
     * @return
     */
    @Override
    public int updateActivity(Activity activity) {
       Activity oldActivity =activityMapper.getActivityById(activity.getId());
       int i=activityMapper.updateActivity(activity);
       //结束时间修改任务
        if(activity.getEndTime()!=null&&!activity.getEndTime().equals(oldActivity.getEndTime())){
            String target="activityTask.finish('"+ activity.getId()+"')";
            String jobName="结束任务id"+ activity.getId();
        }
        return i;
    }
    /**
     * 批量删除活动
     * @param ids
     * @return
     */
    @Override
    public int deleteActivityByIds(Long[] ids) {
        return activityMapper.deleteActivityByIds(ids);
    }
}
